# -*- coding: utf-8 -*-
#
# This file is part of KeyExtracta
# <http://code.google.com/p/keyextracta/>.
#
# KeyExtracta is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# KeyExtracta is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with KeyExtracta.  If not, see <http://www.gnu.org/licenses/>.

from PyQt4.QtCore import QCoreApplication
from core import regutils

def getNames(struct):
  """Get name of product"""
  names = []
  for idx, val in enumerate(struct):
    names.append(val['Name:'])
  return names

def formatAllKeys(struct):
  """"""
  s = ''
  for dict in struct:
    s += '%s\n\n' % formatKey(dict)
  return s.rstrip('\n')

def formatKey(dict):
  """Format the key information for display"""
  d = '\n'.join('{} {}'.format(key, val) for key, val in dict.items())
  return d
  
def addHeader(s):
  """Add header information to string for export file"""
  import time
  n = QCoreApplication.applicationName()
  v = QCoreApplication.applicationVersion()
  h = '# %s Version %s' % (n, v)
  t = '# %s' % time.asctime(time.localtime(time.time()))
  return '%s\n%s\n\n%s' % (h, t, s)
  
def formatExportFileName():
  """"""
  import time
  now = time.localtime(time.time())
  t = time.strftime('%Y%m%d%H%M%S', now)
  n = regutils.getComputerName()
  return  '%s-%s' % (n, t)
  
  